<?php
class category_commonModel extends baseModel{
	protected $table = 'category';

    //栏目导航
    public function nav($cid)
    {
        $data = $this->select('','*');
        $cat = new Category(array(
            'cid',
            'pid',
            'name',
            'urlname',
            'cname'));
        if(empty($data)){
             return;
        }
        $i=0;
        foreach ($data as $key => $value) {
            $i++;
            $list[$key]=$value;
            $list[$key]['curl']=api('content','category_curl',$value['cid']);
            $list[$key]['i']=$i;
            
        }
        return $cat->getPath($list, $cid);
    }

    //栏目树
    public function getcat($cid)
    {
        $id = $cid;
        $data = $this->select('','cid,pid,name');
        $cat = new Category(array(
            'cid',
            'pid',
            'name',
            'cname')); //初始化无限分类

        $cat_for = $cat->getTree($data, $id); //获取分类数据树结构
        if(empty($cat_for)){
            return $id;
        }
        foreach ($cat_for as $v) {
            $cat_id .= $v['cid'] . ",";
        }

        if (!empty($cat_id)) {
            return $cat_id . $id;
        } else {
            return $id;
        }
    }

}